/* 3DGo Game
 * Copyright (C) 2008 Roman Hwang, Eugene Melnichek

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation - version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "GTPMove.h"
#include "GTPInterface.h"

#include <cstdlib>
#include <cassert>

////////////////////////////////////////////////////////////////////////////////

GTPMove::GTPMove(const char *_move, Color _color): m_color(_color)
{
	// Check input
	assert(strlen(_move) == 2);
	assert(_toupper(_move[0]) - 'A' > 0 
		   && _toupper(_move[0]) - 'A' < 19
		   && _move[1] > 0
		   && _move[1] < 19);

	// Parse move in char form move to IJ form
	m_j = _move[0] - 'A';
	m_i = GTPInterface::GetInstance()->GetBoardSize() - atoi(_move + 1);
}

/////////////////////////////////////////////////////////////////////////////////

GTPMove::GTPMove(int _i, int _j, Color _color): m_color(_color) 
{
	// Check input
	assert(_i > 0 && _i < 19 && _j > 0 && _j < 19);

	m_i = _i;
	m_j = _j;
}

/////////////////////////////////////////////////////////////////////////////////

void GTPMove::GetChars(char *_output) const
{
	_output[0] = m_j + 'A';
	_itoa(GTPInterface::GetInstance()->GetBoardSize() - m_i, _output + 1, 10);
}

/////////////////////////////////////////////////////////////////////////////////